import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class ObjectDraw extends JApplet  
{
	protected ObjectDrawModel model;
	protected DrawingCanvasView canvas;
	protected boolean isApplet = false;
   
	// Constructors
	public ObjectDraw(boolean isApplet) 
	{ 
		this.isApplet = isApplet;
		if (!isApplet) 
		{
			init();
		}
	}

	public ObjectDraw() 
	{
		// invoked as Applet
		this(true);
	}

	public void init() 
	{
		getContentPane().setLayout(new BorderLayout());
		model = new ObjectDrawModel();
		canvas = createDrawingCanvasView();
		model.addModelListener(canvas);
		getContentPane().add(canvas, BorderLayout.CENTER); 
	}

	protected DrawingCanvasView createDrawingCanvasView() 
	{
		return new DrawingCanvasView(model);
	}

	// Main method
	public static void main(String[] args) 
	{
		JFrame frame = new JFrame();
		frame.setTitle("ObjectDraw First Iteration");
		frame.getContentPane().setLayout(new BorderLayout());
		frame.getContentPane().add(new ObjectDraw(false), BorderLayout.CENTER);
		frame.addWindowListener(new AppCloser());
		frame.pack();
		frame.setSize(600, 400);
		frame.setVisible(true);
	}

	// Inner class AppCloser for terminating application
	// when Close Window button of frame is clicked
	static class AppCloser extends WindowAdapter  
	{
		public void windowClosing(WindowEvent e) 
		{
			System.exit(0);
		}
	}
	// END OF CLASS
}
